var GameData = require('../module/gameData')();
cc.Class({
    extends: cc.Component,

    properties: {
        daoselect1: cc.Sprite,
        daoselect2: cc.Sprite,
        daojubg1: cc.Sprite,
        daojubg2: cc.Sprite,
        _process1: 0,
        _process2: 0,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.begin1 = false;
        this.begin2 = false;
        this.isClick = false;
        this.updateBtn();
        // this.init();

    },
    /*
    * desc: 更新按钮状态 当金币增减或减少时 更新按钮状态
    * author: <zhouzhiwei>
    * @param:
    * date: 2018/12/10
    */
    updateBtn() {
        this.getlocakdata = GameData.getlocalData("fishData");
        if (this.getlocakdata.coinNum < 100) {
            this.isClick = false;
            this.daojubg1.node.active = true;
            this.daojubg2.node.active = true;

        } else {
            this.isClick = true;
            this.daojubg1.node.active = false;
            this.daojubg2.node.active = false;
        }
        this.init();
    },

    init() {
        this.goal_pro = 6;
        this.goal_pro1 = 5;
        this._process1 = 1;
        this._process2 = 1;
        this.daojubg1.node.getComponent(cc.ProgressBar).progress = 1;
        this.daojubg2.node.getComponent(cc.ProgressBar).progress = 1;
        this.daoselect1.node.active = false;
        this.daoselect2.node.active = false;

    },
    selectBtn(evt) {
        var that = this;
        if (this.isClick) {
            let _name = evt.currentTarget.name;
            switch (_name) {
                case "daoju_btn1":
                    if (GameData.GameLayer.isdaojuClick != 1) {
                        that.daoselect1.node.active = true;
                        that.daoselect2.node.active = false;
                        GameData.GameLayer.isdaojuClick = 1;
                    } else {
                        that.daoselect1.node.active = false;
                        GameData.GameLayer.isdaojuClick = 0;
                    }
                    break;
                case "daoju_btn2":
                    if (GameData.GameLayer.isdaojuClick != 2) {
                        that.daoselect2.node.active = true;
                        that.daoselect1.node.active = false;
                        GameData.GameLayer.isdaojuClick = 2;
                    } else {
                        that.daoselect2.node.active = false;
                        GameData.GameLayer.isdaojuClick = 0;
                    }
                    break;
            }
        }
    },
    start() {

    },
    coinUpdate(type) {

        GameData.GameLayer.coinNum.node.parent.getComponent("gamecoin").coinAddEffect(this.getlocakdata.coinNum, this.getlocakdata.coinNum-100);
        this.getlocakdata.coinNum -= 100;
        GameData.savelocalData(this.getlocakdata);
    },
    /*
    * desc: 播放技能冷却动画
    * author: <zhouzhiwei>
    * @param:
    * date: 2018/12/10
    */
    playAction(type) {
        switch (type) {
            case 1:
                this.daoselect1.node.active = false;
                this.daojubg1.node.active = true;
                this.begin1 = true;
                this.isClick = false;
                break;
            case 2:
                this.daoselect2.node.active = false;
                this.daojubg2.node.active = true;
                this.begin2 = true;
                this.isClick = false;
                break;
        }
    },
    update(dt) {
        if (this.begin1) {
            this._process1 -= dt / this.goal_pro;
            this.daojubg1.node.getComponent(cc.ProgressBar).progress = this._process1;
            if (this._process1 <= 0) {
                this._process1 = 0;
                this.daojubg1.node.getComponent(cc.ProgressBar).progress = this._process1;
                this.isClick = true;
                this.begin1 = false;
                this.daoselect1.node.active = false;
                this.updateBtn();
            }

        }
        if (this.begin2) {
            this._process2 -= dt/ this.goal_pro1;
            this.daojubg2.node.getComponent(cc.ProgressBar).progress = this._process2;
            if (this._process2 <= 0) {
                this._process2 = 0;
                this.begin2 = false;
                this.isClick = true;
                this.daoselect2.node.active = false;
                this.daojubg2.node.getComponent(cc.ProgressBar).progress = this._process2;
                this.updateBtn();
            }


        }
    },
});
